/*
 * File: EpisodeBean.java
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package tvseries.beans;

import tvseries.entity.Episode;
import tvseries.utils.DataUtil;
import tvseries.utils.FileUtil;

/**
 * JSF interface bean class for episodes.
 * 
 * @author nish.naidoo@gmail.com
 * 
 */
public class EpisodeBean implements Comparable<EpisodeBean>
{
	private String id = null;
	private int season = -1;
	private int episode = -1;
	private String title = null;
	private String imdbUrl = null;
	private String airDate = null;
	private String summary = null;
	private String releaseYear = null;
	private String nextEpisodeId = null;
	private String prevEpisodeId = null;
	private String status = null;

	private SeriesBean seriesBean = null;

	private String newStatus = null;
	private boolean selected = false;

	public String changeStatus()
	{
		if (newStatus.equals("Automatic"))
		{
			if (FileUtil.exists(this))
				setStatus("Available");
			else
				setStatus("Missing");
		}

		Episode e = DataUtil.getEpisode(getId());
		e.setStatus(newStatus);
		DataUtil.saveEpisode(e);

		return ActionResult.SUCCESS;
	}

	/**
	 * @return the season
	 */
	public int getSeason()
	{
		return season;
	}

	/**
	 * @param season the season to set
	 */
	public void setSeason(int season)
	{
		this.season = season;
	}

	/**
	 * @return the episode
	 */
	public int getEpisode()
	{
		return episode;
	}

	/**
	 * @param episode the episode to set
	 */
	public void setEpisode(int episode)
	{
		this.episode = episode;
	}

	/**
	 * @return the title
	 */
	public String getTitle()
	{
		return title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title)
	{
		this.title = title;
	}

	/**
	 * @return the imdbUrl
	 */
	public String getImdbUrl()
	{
		return imdbUrl;
	}

	/**
	 * @param imdbUrl the imdbUrl to set
	 */
	public void setImdbUrl(String imdbUrl)
	{
		this.imdbUrl = imdbUrl;
	}

	/**
	 * @return the airDate
	 */
	public String getAirDate()
	{
		return airDate;
	}

	/**
	 * @param airDate the airDate to set
	 */
	public void setAirDate(String airDate)
	{
		this.airDate = airDate;
	}

	/**
	 * @return the summary
	 */
	public String getSummary()
	{
		return summary;
	}

	/**
	 * @param summary the summary to set
	 */
	public void setSummary(String summary)
	{
		this.summary = summary;
	}

	/**
	 * @return the id
	 */
	public String getId()
	{
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id)
	{
		this.id = id;
	}

	/**
	 * @return the releaseYear
	 */
	public String getReleaseYear()
	{
		return releaseYear;
	}

	/**
	 * @param releaseYear the releaseYear to set
	 */
	public void setReleaseYear(String releaseYear)
	{
		this.releaseYear = releaseYear;
	}

	/**
	 * @return the nextEpisodeId
	 */
	public String getNextEpisodeId()
	{
		return nextEpisodeId;
	}

	/**
	 * @param nextEpisodeId the nextEpisodeId to set
	 */
	public void setNextEpisodeId(String nextEpisodeId)
	{
		this.nextEpisodeId = nextEpisodeId;
	}

	/**
	 * @return the prevEpisodeId
	 */
	public String getPrevEpisodeId()
	{
		return prevEpisodeId;
	}

	/**
	 * @param prevEpisodeId the prevEpisodeId to set
	 */
	public void setPrevEpisodeId(String prevEpisodeId)
	{
		this.prevEpisodeId = prevEpisodeId;
	}

	/**
	 * @return the status
	 */
	public String getStatus()
	{
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(String status)
	{
		this.status = status;
	}

	/**
	 * @return the selected
	 */
	public boolean isSelected()
	{
		return selected;
	}

	/**
	 * @param selected the selected to set
	 */
	public void setSelected(boolean selected)
	{
		this.selected = selected;
	}

	/**
	 * @return the series
	 */
	public SeriesBean getSeriesBean()
	{
		return seriesBean;
	}

	/**
	 * @param series the series to set
	 */
	public void setSeriesBean(SeriesBean seriesBean)
	{
		this.seriesBean = seriesBean;
	}

	/**
	 * @return the newStatus
	 */
	public String getNewStatus()
	{
		return newStatus;
	}

	/**
	 * @param newStatus the newStatus to set
	 */
	public void setNewStatus(String newStatus)
	{
		this.newStatus = newStatus;
	}

	public int compareTo(EpisodeBean e)
	{
		if (this.getSeason() - e.getSeason() != 0)
			return this.getSeason() - e.getSeason();

		return this.getEpisode() - e.getEpisode();
	}
}
